interface List {
	readonly id: number;
	name: string;
	[x: string]: any; //字符串索引签名
	age?: number; //可选
}

interface Result {
	data: List[];
}

function render(result: Result) {
	result.data.forEach((value) => {
		console.log(value.id, value.name);
		if (value.age) {
			console.log(value.age);
		}
	});
}
// 方式一
let result = {
	data: [
		{ id: 1, name: 'a', sex: '男' },
		{ id: 2, name: 'b' },
	],
};

render(result);

// 方式二
render({
	data: [
		{ id: 1, name: 'a', sex: '男' },
		{ id: 2, name: 'b' },
	],
} as Result);

// 方式三 react 中容易引起歧义
render(<Result>{
	data: [
		{ id: 1, name: 'a', sex: '男' },
		{ id: 2, name: 'b' },
	],
});

interface StringArray {
	[index: number]: string;
}

interface Names {
	[x: string]: string;
	[y: number]: string;
}
